/* AI聊天悬浮按钮和聊天界面样式 */
/* 优化：使用系统字体减少网络请求 */
* {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

/* 悬浮按钮样式 */
.ai-chat-float-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    z-index: 1000;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    background-image: url('images/./douyan.png');
    background-size: 100%;
    background-position: center;
    background-repeat: no-repeat;
}

.ai-chat-float-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.6);
}

.ai-chat-float-btn:active {
    transform: translateY(0);
}

/* 聊天窗口容器 - 居中大窗口样式（参考DeepSeek） */
.ai-chat-container {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.8);
    width: 800px;
    height: 600px;
    max-width: 90vw;
    max-height: 85vh;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    z-index: 999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid #e0e0e0;
    pointer-events: none;
}

.ai-chat-container.show {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
    pointer-events: auto;
}

/* 添加遮罩层 */
.ai-chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 998;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.ai-chat-overlay.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* 聊天窗口头部 */
.ai-chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-chat-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background-color 0.2s;
}

.ai-chat-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* 聊天消息区域 */
.ai-chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    gap: 20px;
    min-height: 0; /* 重要：修复 flex 容器溢出问题 */
}

/* 滚动条样式 */
.ai-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.ai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 消息样式 */
.chat-message {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    max-width: 100%;
    margin-bottom: 8px;
}

.chat-message.user {
    flex-direction: row-reverse;
}

/* 搜索指示器样式 */
.chat-message.searching {
    opacity: 0.8;
}

.chat-message.searching .chat-bubble {
    background: #e3f2fd;
    color: #1976d2;
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-message.searching .chat-bubble i {
    animation: searchSpin 1.5s linear infinite;
}

@keyframes searchSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: white;
    flex-shrink: 0;
}

.chat-avatar.user {
    background: #667eea;
}

.chat-avatar.ai {
    background: #764ba2;
    background-image: url('images/./douyan.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.chat-bubble {
    max-width: 75%;
    padding: 16px 20px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.6;
    font-size: 15px;
    white-space: pre-wrap; /* 保持换行但忽略多余空格 */
}

.chat-bubble.user {
    background: #667eea;
    color: white;
    border-bottom-right-radius: 6px;
}

.chat-bubble.ai {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* 打字指示器 */
.typing-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    max-width: 70%;
}

.typing-indicator.show {
    display: flex;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 输入区域 */
.ai-chat-input {
    border-top: 1px solid #e0e0e0;
    padding: 20px 24px;
    background: white;
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.chat-input-field {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 24px;
    padding: 12px 20px;
    resize: none;
    outline: none;
    font-family: inherit;
    font-size: 15px;
    max-height: 120px;
    min-height: 48px;
    transition: border-color 0.2s;
    line-height: 1.5;
}

.chat-input-field:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.chat-send-btn {
    width: 48px;
    height: 48px;
    background: #667eea;
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    flex-shrink: 0;
    font-size: 16px;
    font-weight: bold;
}

.chat-send-btn:hover {
    background: #5a6fd8;
}

.chat-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* 欢迎消息 */
.welcome-message {
    text-align: center;
    color: #666;
    font-size: 14px;
    margin: 20px 0;
    padding: 0 20px;
}

/* 错误消息 */
.error-message {
    background: #fee;
    border: 1px solid #fcc;
    color: #c00;
    padding: 10px 15px;
    border-radius: 8px;
    font-size: 13px;
    margin: 10px 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .ai-chat-container {
        width: 95vw;
        height: 80vh;
        transform: translate(-50%, -50%) scale(0.9);
        border-radius: 12px;
    }
    
    .ai-chat-container.show {
        transform: translate(-50%, -50%) scale(1);
    }
    
    .ai-chat-float-btn {
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        font-size: 22px;
    }
}

@media (max-width: 480px) {
    .ai-chat-container {
        width: 98vw;
        height: 85vh;
        border-radius: 8px;
    }
    
    .chat-bubble {
        max-width: 85%;
        font-size: 14px;
        padding: 12px 16px;
    }
    
    .ai-chat-header {
        padding: 16px 20px;
    }
    
    .ai-chat-messages {
        padding: 16px 20px;
    }
    
    .ai-chat-input {
        padding: 16px 20px;
    }
}

/* 消息进入动画 */
.chat-message {
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        transform: translateY(10px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* 流式回答动画 */
.streaming-text {
    animation: typewriter 0.1s;
}

@keyframes typewriter {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 流式输入指示器 */
.stream-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #667eea;
    margin-left: 2px;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* 浮动按钮脉冲效果 */
@keyframes pulse {
    0% {
        box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    }
    50% {
        box-shadow: 0 4px 20px rgba(102, 126, 234, 0.6), 0 0 0 8px rgba(102, 126, 234, 0.1);
    }
    100% {
        box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    }
}

.ai-chat-float-btn.pulse {
    animation: pulse 2s infinite;
}